#include"cmdTask.h"
#include"ThreadPool.h"
#include<stdio.h>
#include"dirStack.h"
#include"mkdir.h"

task_t *_task_init()
{
	task_t *task = (task_t *)malloc(sizeof(task_t));
	bzero(task, sizeof(task_t));
	task->_cmdType = CMD_TYPE_INIT;
	return task;
}

void doTask(task_t *ptask, user_context *puser)
{
	CmdType taskType = ptask->_cmdType;
	int netfd = ptask->_clientFd;
	switch (taskType) {
	case CMD_TYPE_CD:
		cmdCd(ptask, puser); // 传递 netfd 以便与客户端通信
		break;
	case CMD_TYPE_LS:
		cmdLs(ptask, puser);
		break;
	case CMD_TYPE_PWD:
		cmdPwd(ptask, puser);
		break;
	case CMD_TYPE_MKDIR:
		cmdMkdir(ptask, puser);
		break;
	case CMD_TYPE_RMDIR:
		cmdRmdir(ptask, puser);
		break;
	case CMD_TYPE_REMOVE:
		cmdRemove(ptask, puser);
		break;
	case CMD_TYPE_PUTS:
		cmdPuts(ptask, puser); // 需实现文件上传逻辑
		break;
	case CMD_TYPE_GETS:
		cmdGets(ptask, puser); // 需实现文件下载逻辑
		break;
	default:
		printf("Invalid Cmd\n"); // 修正拼写错误
		send(netfd, "ERROR: Invalid Command", 21, 0); // 通知客户端
		break;
	}
}






